# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=phodav
pkgver=2.4
pkgrel=0
pkgdesc="A WebDAV server using libsoup"
url="https://wiki.gnome.org/phodav"
arch="all"
license="LGPL-2.0-or-later"
options="!check" # No test suite
makedepends="asciidoc attr-dev avahi-dev eudev-dev gtk-doc intltool libsoup-dev meson xmlto"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang chezdav chezdav-doc:chezdav_doc
	spice-webdavd:spice spice-webdavd-openrc:spice_openrc"
source="https://download.gnome.org/sources/phodav/$pkgver/phodav-$pkgver.tar.xz
	spice-webdavd.initd
	"

build() {
	meson \
		--prefix=/usr \
		--datadir=share \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--buildtype=plain \
		-Davahi=enabled \
		-Dsystemd=disabled \
		-Dudev=enabled \
		. output
	ninja -C output
}

package() {
	DESTDIR="$pkgdir" ninja -C output install

	rm -rf "$pkgdir"/usr/lib/systemd
}

chezdav() {
	pkgdesc="A simple WebDAV server program"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

chezdav_doc() {
	pkgdesc="A simple WebDAV server program (documentation)"
	mkdir -p "$subpkgdir"/usr/share
	mv "$pkgdir"/../phodav-doc/usr/share/man "$subpkgdir"/usr/share/
}

spice() {
	pkgdesc="Spice daemon for the DAV channel"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/sbin "$subpkgdir"/usr/
	mv "$pkgdir"/lib "$subpkgdir"/
}

spice_openrc() {
	pkgdesc="Spice daemon for the DAV channel (OpenRC init scripts)"
	install_if="spice-webdavd openrc"
	mkdir -p "$subpkgdir"/etc/init.d
	install "$srcdir"/spice-webdavd.initd "$subpkgdir"/etc/init.d/spice-webdavd
}

sha512sums="63f21843ccf62382bc48aa0c7f9ae6882431e59f590da5047f06e8cbbfcf8195744dcfc3b268997bf24ccf1f82f643b8189243f1ec80e60652a03c8c6a0f9b9e  phodav-2.4.tar.xz
1e10314f831840d9f54f38163bd518f42a378fe27b508639771b82610b4a434d4ec56c70a334dbfc7c8cd91160ba346751978f511c522577803248205dbcd211  spice-webdavd.initd"
